<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Controller\Api;

use App\Controller\AbstractController;
use App\Model\Friend;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PostMapping;

#[Controller]
class FriendController extends AbstractController
{
    #[GetMapping(path: '/api/friend/list')]
    public function list()
    {
        $tags = Friend::query()->where('status', 2)->get();

        return success($tags);
    }

    #[PostMapping(path: '/api/friend/apply')]
    public function apply()
    {
        $friend = Friend::query()->create([
            'name' => $this->request->input('name'),
            'url' => $this->request->input('url'),
            'avatar' => $this->request->input('avatar'),
            'info' => $this->request->input('info'),
            'email' => $this->request->input('email'),
            'status' => 1,
        ]);
        return success($friend);
    }
}
